package cn.yunhe.util;

public class PageLimitUtil {
    private static final int PAGESIZE = 2;   //设置分页的每页行数


    public static int getPAGESIZE() {
        return PAGESIZE;
    }

    /**
     * 获取总页数
     * @param totalRows 总行数
     * @return 总页数
     */
    public static int getTotalePage(int totalRows){
        return totalRows%PAGESIZE == 0?(totalRows/PAGESIZE):(totalRows/PAGESIZE+1);
    }

    /**
     * 获取页面索引
     * @param currentPageIndex 当前页面索引
     * @param totalPage 总页数
     * @return 页面索引
     */
    public static int getPageIndex(int currentPageIndex,int totalPage){
        int index;
        if (currentPageIndex>totalPage){
            index = totalPage;
        }else if (currentPageIndex<1){
            index = 1;
        }else {
            index = currentPageIndex;
        }
        return index;
    }

}
